package com.cat.dataStructure03;

/**
*   @description https://leetcode.cn/problems/difference-between-ones-and-zeros-in-row-and-column/
*   @author 曲大人的喵
*   @create 2025/11/7 17:58
*   @since JDK17
*/

public class Solution14 {
    public int[][] onesMinusZeros(int[][] grid) {
        int n = grid.length, m = grid[0].length;
        int[] row = new int[n], col = new int[m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                row[i] += grid[i][j] * 2 - 1;
                col[j] += grid[i][j] * 2 - 1;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                grid[i][j] = row[i] + col[j];
            }
        }

        return grid;
    }
}
